


var slideVerify = '';

get_captcha();

layui.use(function(){
	var layer = layui.layer;
    var util = layui.util;
	getAgreement();		
	
	util.on('lay-on', {
		 
	    'service_agreement': function(){
	        layer.open({
			  type: 1,
			  title: ['服务协议', 'font-size:16px;font-weight: 600'],
			  area: ['920px', '620px'],
			  shade: true, // 显示遮罩
			  content: $('#hide_user_agreement'), // 捕获的元素
			  end: function(){
				// layer.msg('关闭后的回调', {icon:6});
			  }
			});
	    },
		'privacy_policy': function(){
		    layer.open({
			  type: 1,
			  title: ['隐私政策', 'font-size:16px;font-weight: 600'],
			  area: ['920px', '620px'],
			  shade: true, // 显示遮罩
			  content: $('#hide_user_privacy'), // 捕获的元素
			  end: function(){
				// layer.msg('关闭后的回调', {icon:6});
			  }
			});
		},
	})
	

});


function sub(){  
	var datas = '';
	var types    = $('.nav_item.active').attr('data-type')
	var username = $('input[name="username"]').val();
	var password = $('input[name="password"]').val();
	var captcha  = $('input[name="captcha"]').val();
	var captcha2  = $('input[name="captcha2"]').val();
	
	
	if(types == 1){
		if(!username){
			return layer.msg('请输入登录账号')
		}
		if(!password){
			return layer.msg('请输入登录密码')
		}
		if(!captcha){
			return layer.msg('请输入验证码')
		}
		datas = {
			url  :'/api/user/login',
			http_type:'POST',    
			datas:{
				username:username,
				password:password,
				captcha:captcha
			}
		}
	}
	if(types == 2){
		if(!wxx.regPhone(username)){
			return layer.msg('请输入正确的手机号码')
		}
		if(!captcha2){
			return layer.msg('请输入验证码')
		}
		datas = {
			url  :'/api/user/mobilelogin',
			http_type:'POST',    
			datas:{
				username:username,
				captcha:captcha2
			}
		}
	}
	var loadIndex = layer.load(2);
	
	
	
	wxx.HttpReqeust(datas,function(res){
		layer.close(loadIndex)
		if(res.code == 1){
			layer.msg(res.msg)
			localStorage.setItem("jingjiang_userinfo",JSON.stringify(res.data.userinfo));
			localStorage.setItem("jingjiang_token",res.data.userinfo.token);
			setTimeout(function(){
				window.location.href='../../index.html'
			},800)
			
		}else{
			 layer.alert(res.msg,{title:'温馨提示'});
		}
	});
}


$('.code_btns').click(function(){
	get_captcha();
})

function get_captcha(){
	var loadIndex = layer.load(2);
	var datas = {
		url  :'/api/user/captcha',
		http_type:'POST',  
		datas:{id:'1000'}
	}
	wxx.HttpReqeust(datas,function(res){
		layer.close(loadIndex)
		if(res.code == 1){
			$('.code_btns').empty().append('<img src="'+res.data.captcha+'" />')
		}
	});
}


$('.nav_box').on('click', '.nav_item', function(e) {
	var that = $(this)
	var type = that.attr('data-type');
	$('.box_1,.nac_com').show();
	$('.f_title').html('账户登录')
	
	if(!that.hasClass('active')){
		that.siblings().removeClass('active')
		that.addClass('active')
	}
	
	switch (type*1){
		case 1:
			$('.show_type2').hide();
			$('.show_type1').show();
			slideVerify.resetVerify();
			break;
		case 2:
			$('.show_type2').show();
			$('.show_type1').hide();
			in_se();
			slideVerify.resetVerify();
			break;
		
	}
})


$('.Intersect').click(function(){
	$('.f_title').html('账户登录')
	$('.box_1,.nac_com').hide();
	$('.box_2').show();
	// slideVerify.resetVerify();
})

$('.backLo').click(function(){
	$('.box_1,.nac_com').show();
	$('.box_2').hide();
	$('.box_1').show();
})

function yz() {
	var username = $('input[name="username"]').val();
	if(!wxx.regPhone(username)){
		setTimeout(function(){
			slideVerify.resetVerify();
		},300)
		return layer.msg('请输入正确的手机号码')
	}
	
	
}


function in_se(){
	var SlideVerifyPlug = window.slideVerifyPlug;
	slideVerify = new SlideVerifyPlug('#verify-wrap',{
		// wrapWidth:'350',//设置 容器的宽度 ,不设置的话，会设置成100%，需要自己在外层包层div,设置宽度，这是为了适应方便点；
		initText:'请向右滑动发送验证码',  //设置  初始的 显示文字
		sucessText:'验证通过',//设置 验证通过 显示的文字
		getSuccessState:function(res){
			//当验证完成的时候 会 返回 res 值 true，只留了这个应该够用了 
			   console.log(res);
			   yz()
		}
	});
}


function getAgreement(){
	var datas = {
		url  :'/api/user/agreement',
		http_type:'POST',    
		datas:{}
	}
	wxx.HttpReqeust(datas,function(res){
		if(res.code == 1){
			
			$('#hide_user_agreement .emuis').html(res.data.service_agreement)
			$('#hide_user_privacy .emuis2').html(res.data.privacy_policy)
			
		}
	});
}
